//
//  LATableViewCell.m
//  CommodityManager
//
//  Created by libertyair on 15/6/1.
//  Copyright (c) 2015年 libertyair. All rights reserved.
//

#import "LATableViewCell.h"
#import "YRSideViewController.h"

@implementation LATableViewCell

+ (LATableViewCell *)LATableViewCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"left";
    LATableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
        cell = [[LATableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.leftIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-check"]];
        self.titleLabel = [[UILabel alloc]init];
        self.titleLabel.text = @"aaahhahahha";
        self.rightIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-emoji"]];
        
        [self.contentView addSubview:self.leftIcon];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.rightIcon];
        
    }
    return self;
}

#pragma mark - 布局
- (void)layoutSubviews
{
//    LALog(@"%@",NSStringFromCGRect([[[[self superview] superview] superview] frame]));

    YRSideViewController *sss = [[YRSideViewController alloc]init];
    
    CGFloat width = sss.leftViewShowWidth;
    CGFloat height = self.frame.size.height;
    
    //左边按钮
    CGFloat leftIconX = 10;
    CGFloat leftIconY = 10;
    CGFloat leftIconH = height - 2*leftIconY;
    CGFloat leftIconW = leftIconH;
    self.leftIcon.frame = CGRectMake(leftIconX, leftIconY, leftIconW, leftIconH);
    
    //右边按钮
    CGFloat rightIconY = 10;
    CGFloat rightIconH = leftIconH;
    CGFloat rightIconW = rightIconH;
    CGFloat rightIconX = width - 10 - rightIconW;
    self.rightIcon.frame = CGRectMake(rightIconX, rightIconY, rightIconW, rightIconH);
    
    
    //中间文字
    CGFloat titleLabelX = CGRectGetMaxX(self.leftIcon.frame) + 10;
    CGFloat titleLabelY = 10;
    CGFloat titleLabelW = CGRectGetMinX(self.rightIcon.frame) - 10 - titleLabelX;
    CGFloat titleLabelH = leftIconH;
    self.titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
}

- (void)setOFunc:(OtherFunction *)oFunc;
{
    _oFunc = oFunc;
    
    self.leftIcon.image = [UIImage imageNamed:oFunc.leftIcon];
    self.titleLabel.text = oFunc.titleLabel;
    self.rightIcon.image = [UIImage imageNamed:oFunc.rightIcon];
}

@end
